package cn.com.hatech.blog.module.admin.setting.controller;

import cn.com.hatech.blog.common.controller.BaseController;
import cn.com.hatech.blog.module.admin.setting.entity.Setting;
import cn.com.hatech.blog.module.admin.setting.service.IOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @projectName: hatech-blog
 * @package: cn.com.hatech.blog.module.admin.controller
 * @className: SettingController
 * @author: xuruikai
 * @description: 系统配置控制器
 * @date: 2020/1/11 14:27
 * @version: 1.0
 */
@Controller
@RequestMapping("/admin/setting")
@Slf4j
public class SettingPageController extends BaseController {

    @Resource
    private IOptionService optionService;

    /**
     * 系统设置
     */
    @GetMapping(value = "")
    public String setting(HttpServletRequest request) {
        List<Setting> voList = optionService.getOptions();
        Map<String, String> options = new HashMap<>(16);
        voList.forEach(option -> options.put(option.getName(), option.getValue()));
        request.setAttribute("options", options);
        return "admin/setting/setting";
    }

}
